//
//  YSCameraManager.h
//  TakePhotoDemo
//
//  Created by YangShuai on 16/8/31.
//  Copyright © 2016年 ys. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <AssetsLibrary/AssetsLibrary.h>
#import <AVFoundation/AVFoundation.h>

//自定义相机控制类
@interface YSCameraManager : NSObject

+ (instancetype)cameraWithFlashButton:(UIButton *)flashButton;

- (void)startRunning;
- (void)stopRunning;

- (AVCaptureVideoPreviewLayer *)previewLayer;
- (AVCaptureStillImageOutput *)stillImageOutput;

- (void)insertSublayerWithCaptureView:(UIView *)captureView atRootView:(UIView *)rootView;

- (void)changeFlashModeWithButton:(UIButton *)button;

- (void)focusView:(UIView *)focusView inTouchPoint:(CGPoint)touchPoint;

- (void)takePhotoWithCaptureView:(UIView *)captureView
                  effectiveScale:(NSInteger)effectiveScale
                videoOrientation:(AVCaptureVideoOrientation)videoOrientation
                      completion:(void (^)(UIImage *))completion;

- (void)toogleWithFlashButton:(UIButton *)flashButton;
- (AVCaptureDevicePosition)getDevicePosition;
@end

//相册
@interface YSAlbum : NSObject

+ (BOOL)isAvailable;

+ (UIImage *)imageWithMediaInfo:(NSDictionary *)info;
+ (UIImagePickerController *)imagePickerControllerWithDelegate:(id<UINavigationControllerDelegate, UIImagePickerControllerDelegate>)delegate;

@end

//本地照片存储
//Model
@interface YSAssetImageModel : NSObject

@property (strong, nonatomic) NSString *desc;
@property (strong, nonatomic) UIImage *image;
@property (strong, nonatomic) NSString *path;
@property (strong, nonatomic) NSString *title;

- (instancetype)initWithPath:(NSString *)path image:(UIImage *)image;

@end
//
typedef void(^YSAssetsSaveImageCompletion)(NSError* error);
typedef void(^YSAssetsLoadImagesCompletion)(NSArray *items, NSError *error);
//
@interface YSAssetsLibrary : ALAssetsLibrary

+ (YSAssetsLibrary *)defaultAssetsLibrary;

- (void)deleteFile:(YSAssetImageModel *)file;

- (NSArray *)loadImagesFromDocumentDirectory;
- (void)loadImagesFromAlbum:(NSString *)albumName withCallback:(YSAssetsLoadImagesCompletion)callback;

- (void)saveImage:(UIImage *)image completion:(YSAssetsSaveImageCompletion)completion;
- (void)saveImage:(UIImage *)image withAlbumName:(NSString *)albumName completion:(YSAssetsSaveImageCompletion)completion;
- (void)saveJPGImageAtDocumentDirectory:(UIImage *)image;

@end

//闪光灯
@interface YSCameraFlash : NSObject

+ (void)changeModeWithCaptureSession:(AVCaptureSession *)session andButton:(UIButton *)button;
+ (void)flashModeWithCaptureSession:(AVCaptureSession *)session andButton:(UIButton *)button;

@end

//聚焦
@interface YSCameraFocus : NSObject

+ (void)focusWithCaptureSession:(AVCaptureSession *)session touchPoint:(CGPoint)touchPoint inFocusView:(UIView *)focusView;

@end

//拍照
@interface YSCameraShot : NSObject

+ (void)takePhotoCaptureView:(UIView *)captureView
            stillImageOutput:(AVCaptureStillImageOutput *)stillImageOutput
              effectiveScale:(NSInteger)effectiveScale
            videoOrientation:(AVCaptureVideoOrientation)videoOrientation
                  completion:(void (^)(UIImage *photo))completion;

@end

//前后摄像头切换
@interface YSCameraToggle : NSObject

+ (void)toogleWithCaptureSession:(AVCaptureSession *)session;

+ (AVCaptureDevicePosition)getDevicePosition:(AVCaptureSession*)session;

@end
